<?php

namespace App\Http\Controllers\Stock;

use App\Http\Controllers\BaseController;
use App\Models\Stock\StockSub;
use Illuminate\Http\Request;
use App\Services\Stock\Stock as StockStock;
/**
 * 库存子管理
 */
class StockSubController extends BaseController
{

    /**
     * 库存列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getlist(Request $request)
    {
        $list = StockSub::getList($request, $this->mangerinfo['cpid']);
        /****
         * 返回子库存，价格和总价，需要计算
         *
         *
        */
        $price_data=StockStock::getsaleprice($this->mangerinfo['cpid']);
        if (isset($price_data['base']['基价'])) {
            $base_price = $price_data['base']['基价']['amount'];
        }else{
            $base_price=0;
        }

        if(!empty($list['list'])){
            foreach ($list['list'] as $key=>$item){
                $list['list'][$key]['price'] = StockStock::getsteelprice($price_data, $base_price, $item);
                $list['list'][$key]['total_money'] = mathfuncmoney('mul',mathfuncweight('div',$item['total_weight'],1000,4),$list['list'][$key]['price'],0);
            }
        }
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
